package org.jftstool.auxiliar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.jftstool.JFTSFramework;
import org.jftstool.exceptions.JFTSFrameworkException;
import org.jftstool.result.IJFTSResultItem;
import org.jftstool.result.JFTSResult;
import org.jftstool.resultOrder.ResultOrder;
import org.jftstool.searcher.exceptions.JFTSSearcherException;

public class JFTSFrameworkSearchTest {

	
	public static void main(String[] args) {
		JFTSFramework jfts = JFTSFramework.getJFTSInstance();
		try {
			jfts.startSession();
			
			Map<String, String> params = new HashMap<String, String>();

			params.put("type", "field");
			params.put("name", "id");			
			params.put("dir", "desc");
						

			List<Map<String, String>> orders = new ArrayList<Map<String, String>>();
			orders.add(params);
			ResultOrder ro = new ResultOrder(orders);
			

			JFTSResult results = jfts.simpleQuerySearch("content", "clas", ro, 1, 100);
			
			System.out.println("total hits: " + results.getAmount());
	        Iterator<IJFTSResultItem> it = results.getDocuementsIterator();
	        while (it.hasNext()){
	        	IJFTSResultItem item = it.next();
	            System.out.printf(item.getId() + " - ");
	            System.out.printf(item.getCategory() + "\n");
	        }
	        
			jfts.closeSession();
		}
		catch (JFTSFrameworkException e) {
			e.printStackTrace();
		}
		catch (JFTSSearcherException e) {
			e.printStackTrace();
		}
	}
}

